<?php
session_start();
//包含头
include '../PHP/head.php';
?>
<?php
//包含bootstrap的顶端按钮
include '../PHP/menu.php';
?>

<br />
<br />
<p class="text-center lead">报价澄清修改</p>
<?php
//接收clarificaton_id后对其修改
if(isset($_GET['clarification_id'])) {
	require_once ('../FNS/db_fns.php');
	
	$clarification_id = $_GET['clarification_id'];
	
	//数据过滤和处理

	if (! get_magic_quotes_gpc()) {
	$clarification_id=addslashes ($clarification_id);
	}
	
	$db = db_connect();
	$query="select ref, des from clarification where id = '".$clarification_id."'";
	
	$result=$db->query ($query);
	$num_result=$result->num_rows;
	
	//拿出数据
	$row=$result->fetch_assoc ();
	$ref = stripslashes ($row['ref']);
	$des = stripslashes ($row['des']);
	
	$result->free();
	$db->close();
	
	echo "
		<br />
		<form class='form-horizontal' action = '../PHP/edit_clarification.php' method = 'post'>
		<input type='hidden' name = 'clarification_id' value = '".$clarification_id."'>
		<div class='form-group'>
			<label for='ref' class='col-md-3 control-label'>客户文件及章节：</label>
			<div class='col-md-9'>
				<textarea class='form-control' rows='2' name='ref'>".$ref."</textarea>
			</div>
		</div>
		<div class='form-group'>
			<label for='des' class='col-md-3 control-label'>澄清描述：</label>
			<div class='col-md-9'>
				<textarea class='form-control' rows='2' name='des'>".$des."</textarea>
			</div>
		</div>

		<br />
		<div class='form-group'>
			<div class='col-md-offset-3 col-md-9'>
				<input class='btn btn-success' type = 'submit' value='修改'/>
			</div>
		</div>
		</form>
	";
	
}

if (isset($_POST['clarification_id'])) {
		
	require_once ('../FNS/db_fns.php');
	
	$clarification_id = trim($_POST['clarification_id']);
	$ref = trim($_POST['ref']);
	$des = trim($_POST['des']);
			
	//数据过滤和处理
	//加引号避免输入数据库出错
	if (! get_magic_quotes_gpc()) {	
	$clarification_id = addslashes ($clarification_id);
	$ref = addslashes ($ref);
	$des = addslashes ($des);
	}
	
	$issue_date = date('Y-m-d');
	
	//连接数据库并插入数据
	$db = db_connect();
	
	$query="update clarification set ref = '".$ref."', des = '".$des."', status = '提交', issue_date = '".$issue_date."' where id = '".$clarification_id."'";
	$result=$db->query ($query);
	
	//判断是否成功
	if ($result) {
		echo "<br />";
		echo "修改成功。";
	} else {
		echo "<br />";
		echo "修改失败！";
	}
}

?>

</div>
</body>
</html>
